package training;

import java.util.Arrays;
import java.util.List;

/**
 * @Author liangzai
 * @Description:
 */
public class J25_9_26_Training {
    public static void main(String[] args) {
//        boolean[] a = new boolean[3];
          int[] nums = {2,2,3,4};
//        Arrays.sort(nums);
//        System.out.println(Arrays.toString(nums));
        triangleNumber(nums);
        System.out.println(count);
    }

    public static int count = 0;
    public static int[] path = new int[3];
    public static boolean[] std;

    //有效三角形的个数
    public static int triangleNumber(int[] nums) {
        int n = nums.length;
        int count = 0;
        Arrays.sort(nums);
        for (int i = n-1; i >=2 ; i--) {
            int max = nums[i];
            int left = 0; int right = i-1;
            while(left<right){
                if(nums[left]+nums[right]<=max){
                    left++;
                }else {
                    count += right - left;
                    right--;
                }
            }
        }
        return count;
    }

    private static void parent(int[] path,int[] nums,int index){
        if(index>=3){
            if(cheackTriangle(path)){
                count++;
            }
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if(std[i] == true){
                continue;
            }
            path[index] = nums[i];
            index++;
            std[i] = true;
            parent(path,nums,index);
            std[i] = false;
            index--;
            path[index] = 0;
        }
    }

    private static boolean cheackTriangle(int[] nums){
//        int[] nums = new int[3];
//        nums[0] = a; nums[1] = b; nums[2] = c;
        Arrays.sort(nums);
        if(nums[0]+nums[1]<=nums[2] || nums[2]-nums[0]>=nums[1]){
            return false;
        }
        return true;
    }



    public List<List<Integer>> permuteUnique(int[] nums) {

    }
}





